package com.app.service.impl;

import com.app.bean.Ticket;
import com.app.bean.TicketExample;
import com.app.dao.TicketMapper;
import com.app.service.TicketService;
import com.app.util.StringUtilsEx;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 师晓峰
 * @version V1.0
 * @date 2023/9/21 20:06
 * @Description:
 */
@Service
public class TicketServiceImpl implements TicketService {

    @Autowired
    private TicketMapper ticketMapper;


    @Override
    public List<Ticket> list(String moviename) {
        TicketExample ticketExample = new TicketExample();
        TicketExample.Criteria criteria = ticketExample.createCriteria();
        if (StringUtilsEx.isNotEmpty(moviename)){
            criteria.andMovienameLike("%"+moviename+"%");
        }
        List<Ticket> ticketList = ticketMapper.selectByExample(ticketExample);
        return ticketList;
    }

    @Override
    public Ticket getById(String id) {
        return ticketMapper.selectByPrimaryKey(Integer.parseInt(id));
    }

    @Override
    public int add(Ticket ticket) {
        return ticketMapper.insert(ticket);
    }

    @Override
    public int update(Ticket ticket) {
        return ticketMapper.updateByPrimaryKey(ticket);
    }


    @Override
    public int delete(String id) {
        return ticketMapper.deleteByPrimaryKey(Integer.parseInt(id));
    }


}
